package no.rodland.acc.action;

import org.joda.time.DateTime;

import java.util.Map;

import no.rodland.acc.db.FetchService;
import no.rodland.acc.model.AccountGroup;
import no.rodland.acc.model.BankAccount;
import no.rodland.acc.model.BankType;
import no.rodland.acc.model.BudgetAccount;
import no.rodland.acc.model.BudgetAccountGroup;
import no.rodland.acc.model.TextBudgetAccount;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by IntelliJ IDEA.
 *
 * @Since: Jun 18, 2010 10:53:21 AM
 * @Author: fmr
 */
public class ConfigAction extends ActionSupport {
    private final FetchService fetchService;

    private Map<Integer, AccountGroup> accountGroups;
    private Map<Integer, BankAccount> bankAccounts;
    private Map<Integer, BankType> bankTypes;
    private Map<Integer, BudgetAccount> budgetAccounts;
    private Map<Integer, BudgetAccountGroup> budgetAccountGroups;
    private Map<Integer, TextBudgetAccount> textBudgetAccounts;

    public ConfigAction(FetchService fetchService) {
        this.fetchService = fetchService;
    }

    @Override
    public String execute() throws Exception {
        setBankAccount(fetchService.getBankAccounts());
        setAccountGroups(fetchService.getAccountGroups());
        setBankTypes(fetchService.getBankTypes());
        setBudgetAccountGroups(fetchService.getBudgetAccountGroups());
        setBudgetAccounts(fetchService.getBudgetAccounts());
        setTextBudgetAccounts(fetchService.getTextBudgetAccounts());
        return Action.SUCCESS;
    }

    public Map<Integer, BankAccount> getBankAccounts() {
        return bankAccounts;
    }

    private void setBankAccount(Map<Integer, BankAccount> bankAccounts) {
        this.bankAccounts = bankAccounts;
    }

    public Map<Integer, AccountGroup> getAccountGroups() {
        return accountGroups;
    }

    private void setAccountGroups(Map<Integer, AccountGroup> accountGroups) {
        this.accountGroups = accountGroups;
    }

    public Map<Integer, BankType> getBankTypes() {
        return bankTypes;
    }

    private void setBankTypes(Map<Integer, BankType> bankTypes) {
        this.bankTypes = bankTypes;
    }

    public Map<Integer, BudgetAccount> getBudgetAccounts() {
        return budgetAccounts;
    }

    private void setBudgetAccounts(Map<Integer, BudgetAccount> budgetAccounts) {
        this.budgetAccounts = budgetAccounts;
    }

    public Map<Integer, BudgetAccountGroup> getBudgetAccountGroups() {
        return budgetAccountGroups;
    }

    private void setBudgetAccountGroups(Map<Integer, BudgetAccountGroup> budgetAccountGroups) {
        this.budgetAccountGroups = budgetAccountGroups;
    }

    public Map<Integer, TextBudgetAccount> getTextBudgetAccounts() {
        return textBudgetAccounts;
    }

    public void setTextBudgetAccounts(Map<Integer, TextBudgetAccount> textBudgetAccounts) {
        this.textBudgetAccounts = textBudgetAccounts;
    }

    public DateTime getMyDate(){
         return this.budgetAccountGroups.get(1).getCreatedDate();
    }
    public DateTime getMyTestDate(){
         return this.budgetAccountGroups.get(3).getCreatedDate();
    }
}
